from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-09-25 14:12:19.997089
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Sat, 25, Sep, 2021
Time: 14:12:25
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -46.3584
Nobs: 425.000 HQIC: -46.8775
Log likelihood: 4696.06 FPE: 3.12015e-21
AIC: -47.2165 Det(Omega_mle): 2.53088e-21
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.423791 0.091848 4.614 0.000
L1.Burgenland 0.106435 0.047656 2.233 0.026
L1.Kärnten -0.113663 0.023849 -4.766 0.000
L1.Niederösterreich 0.160463 0.101998 1.573 0.116
L1.Oberösterreich 0.117602 0.100165 1.174 0.240
L1.Salzburg 0.283775 0.050065 5.668 0.000
L1.Steiermark 0.027567 0.066733 0.413 0.680
L1.Tirol 0.106062 0.052589 2.017 0.044
L1.Vorarlberg -0.102045 0.047118 -2.166 0.030
L1.Wien -0.003826 0.091336 -0.042 0.967
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.010693 0.210350 0.051 0.959
L1.Burgenland -0.049558 0.109141 -0.454 0.650
L1.Kärnten 0.037136 0.054618 0.680 0.497
L1.Niederösterreich -0.209710 0.233596 -0.898 0.369
L1.Oberösterreich 0.485520 0.229397 2.117 0.034
L1.Salzburg 0.307779 0.114660 2.684 0.007
L1.Steiermark 0.108758 0.152831 0.712 0.477
L1.Tirol 0.312482 0.120439 2.595 0.009
L1.Vorarlberg 0.001828 0.107910 0.017 0.986
L1.Wien 0.006565 0.209178 0.031 0.975
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.242596 0.046492 5.218 0.000
L1.Burgenland 0.091548 0.024122 3.795 0.000
L1.Kärnten -0.001887 0.012072 -0.156 0.876
L1.Niederösterreich 0.211833 0.051630 4.103 0.000
L1.Oberösterreich 0.159825 0.050702 3.152 0.002
L1.Salzburg 0.034886 0.025342 1.377 0.169
L1.Steiermark 0.021502 0.033779 0.637 0.524
L1.Tirol 0.069250 0.026620 2.601 0.009
L1.Vorarlberg 0.059073 0.023850 2.477 0.013
L1.Wien 0.112858 0.046233 2.441 0.015
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.184587 0.045554 4.052 0.000
L1.Burgenland 0.047989 0.023636 2.030 0.042
L1.Kärnten -0.006506 0.011828 -0.550 0.582
L1.Niederösterreich 0.141199 0.050588 2.791 0.005
L1.Oberösterreich 0.316550 0.049679 6.372 0.000
L1.Salzburg 0.100715 0.024831 4.056 0.000
L1.Steiermark 0.129886 0.033097 3.924 0.000
L1.Tirol 0.077046 0.026082 2.954 0.003
L1.Vorarlberg 0.055724 0.023369 2.385 0.017
L1.Wien -0.047384 0.045300 -1.046 0.296
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.204467 0.090320 2.264 0.024
L1.Burgenland -0.046638 0.046863 -0.995 0.320
L1.Kärnten -0.034255 0.023452 -1.461 0.144
L1.Niederösterreich 0.111507 0.100302 1.112 0.266
L1.Oberösterreich 0.164690 0.098499 1.672 0.095
L1.Salzburg 0.251335 0.049233 5.105 0.000
L1.Steiermark 0.078834 0.065623 1.201 0.230
L1.Tirol 0.126239 0.051714 2.441 0.015
L1.Vorarlberg 0.115745 0.046335 2.498 0.012
L1.Wien 0.031850 0.089817 0.355 0.723
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.033522 0.069661 0.481 0.630
L1.Burgenland 0.022930 0.036144 0.634 0.526
L1.Kärnten 0.054131 0.018088 2.993 0.003
L1.Niederösterreich 0.208679 0.077359 2.698 0.007
L1.Oberösterreich 0.339286 0.075969 4.466 0.000
L1.Salzburg 0.045216 0.037971 1.191 0.234
L1.Steiermark -0.009661 0.050612 -0.191 0.849
L1.Tirol 0.112839 0.039885 2.829 0.005
L1.Vorarlberg 0.069691 0.035736 1.950 0.051
L1.Wien 0.124286 0.069273 1.794 0.073
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.194013 0.085357 2.273 0.023
L1.Burgenland 0.015197 0.044288 0.343 0.731
L1.Kärnten -0.057220 0.022163 -2.582 0.010
L1.Niederösterreich -0.116428 0.094790 -1.228 0.219
L1.Oberösterreich 0.194281 0.093086 2.087 0.037
L1.Salzburg 0.032742 0.046527 0.704 0.482
L1.Steiermark 0.285838 0.062016 4.609 0.000
L1.Tirol 0.490185 0.048872 10.030 0.000
L1.Vorarlberg 0.076822 0.043788 1.754 0.079
L1.Wien -0.112687 0.084881 -1.328 0.184
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.158964 0.093276 1.704 0.088
L1.Burgenland -0.012652 0.048397 -0.261 0.794
L1.Kärnten 0.063702 0.024220 2.630 0.009
L1.Niederösterreich 0.196227 0.103585 1.894 0.058
L1.Oberösterreich -0.129056 0.101723 -1.269 0.205
L1.Salzburg 0.236449 0.050844 4.650 0.000
L1.Steiermark 0.149046 0.067770 2.199 0.028
L1.Tirol 0.049585 0.053407 0.928 0.353
L1.Vorarlberg 0.132992 0.047851 2.779 0.005
L1.Wien 0.157016 0.092757 1.693 0.090
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.481984 0.050615 9.522 0.000
L1.Burgenland -0.006186 0.026262 -0.236 0.814
L1.Kärnten -0.009444 0.013143 -0.719 0.472
L1.Niederösterreich 0.203905 0.056209 3.628 0.000
L1.Oberösterreich 0.254130 0.055199 4.604 0.000
L1.Salzburg 0.022496 0.027590 0.815 0.415
L1.Steiermark -0.023285 0.036775 -0.633 0.527
L1.Tirol 0.067038 0.028981 2.313 0.021
L1.Vorarlberg 0.061735 0.025966 2.378 0.017
L1.Wien -0.049737 0.050334 -0.988 0.323
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.022430 0.077599 0.139985 0.133356 0.042713 0.075164 0.001895 0.183265
Kärnten 0.022430 1.000000 -0.044129 0.128550 0.047444 0.071634 0.454153 -0.091075 0.090923
Niederösterreich 0.077599 -0.044129 1.000000 0.283240 0.081965 0.268929 0.018682 0.137597 0.260779
Oberösterreich 0.139985 0.128550 0.283240 1.000000 0.178246 0.291118 0.156884 0.102535 0.137990
Salzburg 0.133356 0.047444 0.081965 0.178246 1.000000 0.124764 0.055758 0.106597 0.051360
Steiermark 0.042713 0.071634 0.268929 0.291118 0.124764 1.000000 0.131232 0.092754 -0.016252
Tirol 0.075164 0.454153 0.018682 0.156884 0.055758 0.131232 1.000000 0.046114 0.118372
Vorarlberg 0.001895 -0.091075 0.137597 0.102535 0.106597 0.092754 0.046114 1.000000 -0.045801
Wien 0.183265 0.090923 0.260779 0.137990 0.051360 -0.016252 0.118372 -0.045801 1.000000